package com.example.shop_2305.adapter

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.lib_base.entity.Order
import com.example.shop_2305.R

class OrderAdapter:BaseQuickAdapter<Order,BaseViewHolder>(R.layout.item_order) {
    override fun convert(holder: BaseViewHolder, item: Order) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.totalNum}件商品，总金额:￥${item.payPrice}")

        val rv = holder.getView<RecyclerView>(R.id.order_rv)
        val orderChildAdapter = OrderChildAdapter()
        orderChildAdapter.data.addAll(item.orderInfoList)
        rv.adapter = orderChildAdapter
        rv.layoutManager = LinearLayoutManager(context)

        if(item.orderStatus=="待支付"){
            holder.getView<TextView>(R.id.order_tv2).text = "去支付"
        }else if(item.orderStatus=="待发货"){
            holder.getView<TextView>(R.id.order_tv2).text = "催发货"
            holder.getView<TextView>(R.id.order_tv1).text = "申请售后"
        }else if(item.orderStatus=="待评价"){
            holder.getView<TextView>(R.id.order_tv2).text = "去评价"
        }else{
            holder.getView<TextView>(R.id.order_tv2).text = "查看详情"
        }
    }
}